/**
* Don't edit this file manually 
* Modify at 2024-10-31 09:24:43
*/
;var _select_org_version_ = 'traditional';
/**
 * @name		选人组件插件
 * @author		shuqi
 * @version 	1.0
 * @date  		2017-01-08
 */
; (function ($) {
	// 默认使用vue模式
	if (!window._select_org_version_) {
		// 后端枚举 com.seeyon.ctp.organization.selectorg.SelectOrgConstants.SelectOrgType
		window._select_org_version_ = "vue";//traditional|vue
	}
	// 基础数据多环境兼容
	var _isZXClient = !!window.top.ZX_CLIENT;
	// env 变量
	var _resSuffix = window._resSuffix ? window._resSuffix : ("?_t=" + new Date().getTime());
	var _selectOrgPath = window.isVjoinSelectOrg ? window._v5Path : (window._ctxPath ? window._ctxPath : "/seeyon");
	var _csrfGuard = window.CsrfGuard || (window.ctpTop && window.ctpTop.CsrfGuard);
	// 选人弹出的窗口
	var _targetWindow = window.getCtpTop ? window.getCtpTop() : (window.getA8Top ? window.getA8Top() : window.top);
	// IE 判断
	var isIE = (navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0);
	var isIE8 = isIE && /msie 8\.0/i.test(navigator.userAgent) || (navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0) && /msie 7\.0/i.test(navigator.userAgent);
	// 是否使用默认的zIndexd
	var _useDefaultIndex =_isZXClient || !!window.isVjoinSelectOrg;
	// 依赖jQuery走回调
	var jqueryCallback = function(callback){
		callback();
	};
	// 生成默认的_csrfGuard
	if (!_csrfGuard) {
		_csrfGuard = {
			getToken: function () {
				return "";
			},
			isEnabled: function () {
				return this.getToken() !== '';
			},
			getUrlSurffix: function (url) {
				return "";
			},
			beforeAjaxSend: function (request) {
			}
		};
	}
	// url后缀
	var _urlSurffix = _csrfGuard.getUrlSurffix();

	// 是否为致信客户端，加载sdk
	if(_isZXClient){
		var zxWindow = window.top;
		_selectOrgPath = zxWindow.ZX.$store.getters.getBaseURL + _selectOrgPath;
		_targetWindow = zxWindow;
		if(zxWindow !== window && !zxWindow.selectOrgSdk){
			// 致信top 不存在选人，则加载致信
			var spt = zxWindow.document.createElement('script');
			spt.setAttribute('type', 'text/javascript');
			spt.setAttribute('src', _selectOrgPath + '/common/js/selectOrgSdk.js' + _resSuffix + _urlSurffix);
			var headTags = zxWindow.document.getElementsByTagName("head");
			if (headTags) {
				headTags[0].appendChild(spt);
			} else {
				throw "Get Head Error";
			}
		}
	}

	// 依赖jquery加载
	if (typeof $ === "undefined") {
		var callbackStack = [];
		var spt = document.createElement('script');
		spt.setAttribute('type', 'text/javascript');
		spt.setAttribute('src', _selectOrgPath + '/common/js/jquery-debug.js' + _resSuffix + _urlSurffix);
		spt.onload = function () {
			$ = window.jQuery;
			if(callbackStack.length > 0){
				for (var i = 0,len = callbackStack.length; i < len; i++) {
					callbackStack[i]();
				}
			}
			jqueryCallback = function(callback){
				callback();
			};
		};
		var headTags = document.getElementsByTagName("head");
		if (headTags) {
			headTags[0].appendChild(spt);
		} else {
			throw "Get Head Error";
		}
		jqueryCallback = function (callback){
			callbackStack.push(callback);
		}
	}

	// div样式处理
	var link = _targetWindow.document.getElementById("selectOrgSdkCss");
	if (!link) {
		var style = _targetWindow.document.createElement("link");
		style.setAttribute('id', 'selectOrgSdkCss');
		style.setAttribute('type', 'text/css');
		style.setAttribute('rel', 'stylesheet');
		style.setAttribute('href', _selectOrgPath + '/common/js/selectOrgSdk.css' + _resSuffix + _urlSurffix);
		var headTags = _targetWindow.document.getElementsByTagName("head");
		if (headTags) {
			headTags[0].appendChild(style);
		} else {
			throw "Get Head Error";
		}
	}

	/*vjoin使用不了i18n*/
	var vjoinI18n = {
		"selectPeople.flowtype.concurrent.lable": "并发",
		"selectPeople.flowtype.sequence.lable": "串发",
		"selectPeople.flowtype.multiple.lable": "多层",
		"selectPeople.flowtype.colAssign.lable": "会签",
		"common.button.ok.label": "确定",
		"common.button.clear.label": "清空",
		"common.button.cancel.label": "取消",
		"common.pleaseSelect.label": "请选择",
	}
	/** 兼容V3x */
	function _i18n(key) {
		var rs = "";
		if ($.i18n) {
			rs = $.i18n(key);
		} else if (top && top.$.i18n) {
			rs = top.$.i18n(key);
		} else if (typeof CTPLang !== "undefined" && typeof _locale !== "undefined") {
			rs = CTPLang[_locale][key];
		}
		if (rs === "") {
			rs = vjoinI18n[key];
		}
		if (typeof rs == "undefined") {
			rs = key;
		}
		return rs;
	}

	/**
	 * 工具方法
	 * @type {{debug: Utils.debug, log: Utils.log, debugAble: boolean, error: Utils.error}}
	 */
	var Utils = {
		debugAble: false,
		log: function () {
			console && console.log && console.log(arguments)
		},
		debug: function () {
			if (Utils.debugAble) {
				console && console.debug && console.debug(arguments)
			}
		},
		error: function () {
			console && console.error && console.error(arguments)
		},
	}

	/**
	 * 判断对象是否包含指定class
	 * @param $obj jquery对象
	 * @param className
	 * @returns {boolean|*}
	 */
	function hasClass($obj, className) {
		if (!$obj) {
			return false;
		}
		var cssClass = $obj.attr("class");
		if (!cssClass) {
			return false;
		}
		var classes = cssClass.split(" ");
		return classes.indexOf(className) !== -1;
	}

	/**
	 * @param eventObj maybeEvent
	 * @returns {Event}
	 * @private
	 */
	function stopAndReturn(eventObj) {
		var _eventObj = eventObj ? eventObj : window.event;
		_eventObj.preventDefault && eventObj.preventDefault();
		_eventObj.stopPropagation && eventObj.stopPropagation();
		_eventObj.cancelBubble = true;
		return _eventObj;
	}

	/**
	 * 可拖拽实现
	 * @param opt 参数{targetWindow:目标窗口,actionPanel:触发dom,targetPanel:移动dom}
	 * @constructor
	 */
	var DraggAble = function (opt) {
		this.opt = opt;
		if (!this.opt.targetWindow) {
			this.opt.targetWindow = window;
		}
		this._init();
	}

	/**
	 * 获取dom style
	 * @param dom dom
	 * @param attrName 属性
	 * @returns {string|*}
	 */
	DraggAble.prototype._getStyle = function (dom, attrName) {
		var _document = this.opt.targetWindow.document;
		if (_document.defaultView) {
			return _document.defaultView.getComputedStyle(dom, null).getPropertyValue(attrName);
		}
		else if (dom.currentStyle) {
			return dom.currentStyle[attrName];
		}
		return undefined;
	}

	/**
	 * 获取dom 数字类型style
	 * @param dom dom
	 * @param attrName 属性
	 * @returns {string|*}
	 */
	DraggAble.prototype._getStyleNum = function (dom, attrName) {
		var styleVal = this._getStyle(dom, attrName);
		if (styleVal) {
			return parseInt(styleVal);
		}
		return 0;
	}

	/**
	 * 初始化
	 * @private
	 */
	DraggAble.prototype._init = function () {
		var params = {
			currentX: 0,
			currentY: 0,
			left: 0,
			top: 0,
			dragFlag: false,
			actionMove: null,
			actionEnd: null,
			noSelect: function (eventObj) {
				return false;
			}
		};
		/**
		 * conetxt bind
		 * @param handle handler
		 * @param context  context
		 * @returns {function(*): *}
		 */
		function bind(handle, context) {
			return function (eventObj) {
				return handle.apply(this, [eventObj, context]);
			}
		}
		/**
		 * 鼠标移动
		 * @param event eventObj
		 * @param context eventContext
		 * @private
		 */
		function _dragMove(event, context) {
			if (!params.dragFlag) {
				return;
			}
			var _eventObj = stopAndReturn(event);
			var nowX = _eventObj.clientX, nowY = _eventObj.clientY;
			var disX = nowX - params.currentX, disY = nowY - params.currentY;
			var left = parseInt(params.left) + disX, top = parseInt(params.top) + disY;

			// 避免移除边界
			if (left > params.MaxWidth) {
				left = params.MaxWidth;
			}
			if (left < 0) {
				left = 0;
			}
			if (top > params.maxTop) {
				top = params.maxTop;
			}
			if (top < 0) {
				top = 0;
			}
			// change target
			var _targetPanel = context.targetPanel;
			_targetPanel.style.left = left + "px";
			_targetPanel.style.top = top + "px";

		}
		/**
		 * 结束移动
		 * @param event eventObj
		 * @param context eventContext
		 * @private
		 */
		function _dragEnd(event, context) {
			Utils.debug("_dragEnd ==>", event, context);

			var _eventObj = stopAndReturn(event);

			var dragObj = context.dragObj;
			var targetPanel = context.targetPanel;
			var actionPanel = context.actionPanel;
			var moveMask = context.moveMask;
			var _document = context.targetWindow.document;

			moveMask.style.display = "none"

			// unbind event
			DraggAble.off("mousemove", params.actionMove, _document);
			DraggAble.off("mouseup", params.actionEnd, _document);
			DraggAble.off("selectstart", params.noSelect, _document);

			// updateState
			params.left = dragObj._getStyleNum.apply(dragObj, [targetPanel, "left"]);
			params.top = dragObj._getStyleNum.apply(dragObj, [targetPanel, "top"]);
			params.currentX = _eventObj.clientX;
			params.currentY = _eventObj.clientY;
			params.actionMove = null;
			params.actionEnd = null;
			params.dragFlag = false;
		}

		/**
		 * 选中actionPanel
		 * @param event eventObj
		 * @param context eventContext
		 * @private
		 */
		function _dragStart(event, context) {
			Utils.debug("_dragStart ==>", event, context);

			var _eventObj = stopAndReturn(event);

			var _targetWindow = context.targetWindow;
			var dragObj = context.dragObj;
			var targetPanel = context.targetPanel;
			var actionPanel = context.actionPanel;
			var moveMask = context.moveMask;
			var _document = _targetWindow.document;

			// 可视区域高度
			var clientHeight = _targetWindow.innerHeight || _targetWindow.document.documentElement.clientHeight || _targetWindow.document.body.clientHeight;
			// 可视区域宽度
			var clientWidth = _targetWindow.innerWidth || _targetWindow.document.documentElement.clientWidth || _targetWindow.document.body.clientWidth;


			// 更新遮罩
			moveMask.style.display = "block";

			// updateState
			params.left = dragObj._getStyleNum.apply(dragObj, [targetPanel, "left"]);
			params.top = dragObj._getStyleNum.apply(dragObj, [targetPanel, "top"]);
			params.currentX = _eventObj.clientX;
			params.currentY = _eventObj.clientY;
			params.maxTop = clientHeight - 55;
			params.MaxWidth = clientWidth - 55;
			params.actionMove = bind(_dragMove, context);
			params.actionEnd = bind(_dragEnd, context);
			params.dragFlag = true;

			// bind event
			DraggAble.on("mousemove", params.actionMove, _document);
			DraggAble.on("mouseup", params.actionEnd, _document);
			DraggAble.on("selectstart", params.noSelect, _document);
		}

		var _actionPanel = this.opt.actionPanel;
		var context = {
			dragObj: this,
			actionPanel: _actionPanel,
			targetPanel: this.opt.targetPanel,
			moveMask: this.opt.moveMask,
			targetWindow: this.opt.targetWindow,
		}

		this.opt.actionStart = bind(_dragStart, context);
		DraggAble.on("mousedown", this.opt.actionStart, _actionPanel)
	}

	/**
	 * 绑定事件
	 * @param eventName 事件对象
	 * @param handle 事件处理
	 * @param dom 目标dom
	 */
	DraggAble.on = function (eventName, handle, dom) {
		var _dom = dom;
		if (document.addEventListener) {
			_dom.addEventListener(eventName, handle, false);
		} else {
			_dom.attachEvent("on" + eventName, handle);
		}
	}

	/**
	 * 取消事件绑定
	 * @param eventName 事件对象
	 * @param handle 事件处理
	 * @param dom 目标dom
	 */
	DraggAble.off = function (eventName, handle, dom) {
		if (document.removeEventListener) {
			dom.removeEventListener(eventName, handle);
		} else {
			dom.detachEvent("on" + eventName, handle);
		}
	}

	/**
	 * 销毁对象
	 */
	DraggAble.prototype.destroy = function () {
		var _actionPanel = this.opt.actionPanel;
		var actionStart = this.opt.actionStart;
		DraggAble.off("mousedown", actionStart, _actionPanel);

		this.opt.actionStart = null;
		this.opt = null;

	}

	window._selectOrgInstance_ = null;
	var selectOrg = {};
	var CLASS_NAME_DISABLED = "disabled";
	/** 初始化选人dialog dom */
	selectOrg.getDialogBody = function (opt) {
		var _targetWindow = opt.targetWindow;
		// 可视区域高度
		var clientHeight = _targetWindow.innerHeight || _targetWindow.document.documentElement.clientHeight || _targetWindow.document.body.clientHeight;
		// 可视区域宽度
		var clientWidth = _targetWindow.innerWidth || _targetWindow.document.documentElement.clientWidth || _targetWindow.document.body.clientWidth;
		var dialogHeight = 535;
		var dialogWidth = 840;
		if (_select_org_version_ === "traditional") {
			// 老选人界面
			dialogHeight = 506;
			dialogWidth = 820;
		}
		// 高宽
		var warpHeight = dialogHeight + 50 + 55;
		if (clientHeight < warpHeight) {
			warpHeight = clientHeight;
			dialogHeight = warpHeight - 55 - 50;
		}
		// 绝对定位
		var ptop = (clientHeight - warpHeight) / 2.0;
		var pleft = (clientWidth - dialogWidth) / 2.0;

		var okLabel = _i18n('common.button.ok.label');
		var cancelLabel = _i18n('common.button.cancel.label');
		// 计算z-index
		var dialogIndex = _targetWindow.getMaxZindex && _targetWindow.getMaxZindex(1);
		if (_useDefaultIndex || !dialogIndex) {
			// vjoin 暂时固定
			dialogIndex = 99999999;
		}
		var contentStyle = "height:" + dialogHeight + "px;";
		var warpStyle = "top:" + ptop + "px;left:" + pleft + "px;height:" + warpHeight + "px;width:" + dialogWidth + "px;z-index:" + dialogIndex + ";";
		var body = '\
			<iframe id="selectPeopleIframe_' + opt.id + '" class="selectorgIframe" allowtransparency="true" src="about:blank" frameborder="0" style="z-index:' + dialogIndex + '" scrolling="no"></iframe>\
			<div id="selectPeopleMove_' + opt.id + '" class="selectorg-move" style="-webkit-app-region:no-drag;"></div>\
			<div class="selectorg-shade" id="selectPeopleShade_' + opt.id + '" style="-webkit-app-region:no-drag;z-index:' + dialogIndex + '; "></div>\
			<div class="selectorg selectorg-' + window._select_org_version_ + '" id="selectPeople_' + opt.id + '" style="-webkit-app-region:no-drag;' + warpStyle + '">\
				<div class="selectorg-title" style="-webkit-app-region:no-drag;">\
					<span class="default-label" style="display: none;">' + _i18n("common.pleaseSelect.label") + '</span>\
					<div class="account-label" style="background: url(' + _selectOrgPath + '/common/organization/img/org-account.png) no-repeat;background-position:0px ' + (window.isVjoinSelectOrg ? "8" : "12") + 'px;background-size: 26px 26px;">\
						<span class="account-name" >单位名</span>\
						<span class="selectorg-arrow-down rolling_btn_b"></span>\
					</div>\
				</div>\
				<div  class="selectorg-content" style="-webkit-app-region:no-drag;">\
					<iframe scrolling="auto" allowtransparency="true"  id="selectPeopleFrane_' + opt.id + '" frameborder="0" \
						src="' + opt.url + '" \
						style="' + contentStyle + '"></iframe>\
				</div>\
				<span class="selectorg-setwin" style="-webkit-app-region:no-drag;">\
					<a class="selectorg-close"></a>\
				</span>\
				<div class="selectorg-btn" style="-webkit-app-region:no-drag;">\
					<a class="button emphasize ok" title="' + okLabel + '">' + okLabel + '</a>\
					<a class="button gray cancel" title="' + cancelLabel + '">' + cancelLabel + '</a>\
					<div class="flowbtns"></div>\
				</div>\
				<div class="bar-mask topbar-mask"></div>\
				<div class="bar-mask bottombar-mask"></div>\
			</div>\
		';
		body = body.replace(/\t/gi, "");
		var $body = _targetWindow.$(body);
		if (_select_org_version_ === "traditional") {
			$body.find(".clear").hide();
			$body.find(".default-label").show();
		}
		return $body;
	}
	/** 流程图的dom */
	selectOrg.getFlowBtn = function (context) {
		var ieStyle = "not-ie";
		if (isIE && isIE8) {
			ieStyle = "";
		}
		var flowBtns = "\
		<table id='flowTypeDiv' class='hidden " + ieStyle + "' width='' border='0' height='20' align='center' cellpadding='0' cellspacing='0'>\
			<tr>\
				<td id='concurrentType'>\
					&nbsp;&nbsp;&nbsp;&nbsp;\
					<label for='concurrent' class='flow-radio'>\
						<input id='concurrent' name='flowtype' type='radio' value='1' checked>&nbsp;\
						<span>" + _i18n("selectPeople.flowtype.concurrent.lable") + "</span>\
					</label>&nbsp;&nbsp;&nbsp;\
				</td>\
				<td id='sequenceType'>\
					<label for='sequence' class='flow-radio'>\
						<input id='sequence' name='flowtype' type='radio' value='0'>&nbsp;\
						<span>" + _i18n("selectPeople.flowtype.sequence.lable") + "</span>\
					</label>&nbsp;&nbsp;&nbsp;\
				</td>\
				<td id='multipleType' >\
					<label for='multiple' class='flow-radio'>\
						<input id='multiple' name='flowtype' type='radio' value='2'>&nbsp;\
						<span>" + _i18n("selectPeople.flowtype.multiple.lable") + "</span>\
			        </label>&nbsp;&nbsp;&nbsp;\
				</td>\
				<td id='colAssignType' >\
					<label for='colAssign' class='flow-radio'>\
						<input id='colAssign' name='flowtype' type='radio' value='3'>&nbsp;\
						<span>" + _i18n("selectPeople.flowtype.colAssign.lable") + "</span>\
					</label>&nbsp;&nbsp;&nbsp;\
				</td>\
			</tr>\
		</table>\
		<table id='flowTextDiv' name='flowTextDiv' class='hidden' width='' border='0' height='20' align='center' cellpadding='0' cellspacing='0'>\
			<tr>\
				<td><span id='flowText'></span></td>\
			</tr>\
		</table>";
		// 去掉 \t
		flowBtns = flowBtns.replace(/\t/gi, "");
		var options = context.options;
		var _targetWindow = context.targetWindow;
		var $flowBtns = _targetWindow.$(flowBtns);

		var showFlowText = options.showFlowText;
		var flowText = options.flowText ? options.flowText : "";
		if (showFlowText) {
			var $flowTextDiv = $flowBtns.eq(1).removeClass("hidden");
			$flowTextDiv.find("#flowText").html(flowText);
		}

		var showFlowTypeRadio = options.showFlowTypeRadio;
		//优先显示文本内容，没有文本内容，再处理显示选项（并发，串发..） 许树祥
		if (!showFlowText && showFlowTypeRadio) {
			var $flowTypeDiv = $flowBtns.eq(0).removeClass("hidden");


			var invalidationMultipleRadio = options.invalidationMultipleRadio;
			if (invalidationMultipleRadio === true) {
				$flowBtns.find("#multipleType input").prop("disabled", true);
			}
			var hiddenMultipleRadio = options.hiddenMultipleRadio;
			if (hiddenMultipleRadio === true) {
				$flowBtns.find("#multipleType").css("display", "none");
			}
			var invalidationColAssignRadio = options.invalidationColAssignRadio;
			if (invalidationColAssignRadio === true) {
				$flowBtns.find("#colAssignType input").prop("disabled", true);
			}
			var hiddenColAssignRadio = options.hiddenColAssignRadio;
			if (hiddenColAssignRadio === true) {
				$flowBtns.find("#colAssignType").css("display", "none");
			}

			var _flowtype = options.flowtype;
			if (_flowtype) {
				var $flowtype = $flowBtns.find("#" + _flowtype)
				if ($flowtype.length > 0) {
					$flowtype.prop("checked", true);
				}
			}
		}
		return $flowBtns;
	}

	/** 初始化dom事件 */
	selectOrg.initEvent = function (context) {
		var $dialogBody = context.targetWindow.$("#selectPeople_" + context.id);
		var $dialogTitle = $dialogBody.find(".selectorg-title");
		var $dialogMove = context.targetWindow.$("#selectPeopleMove_" + context.id);
		var $dialogMask = context.targetWindow.$("#selectPeopleShade_" + context.id);
		selectOrg._dragObj = new DraggAble({
			actionPanel: $dialogTitle[0],
			targetPanel: $dialogBody[0],
			moveMask: $dialogMove[0],
			targetWindow: context.targetWindow
		});

		/** 确定*/
		$dialogBody.find(".ok").bind("click", context, function (event) {
			var contextData = event.data;
			var _targetWindow = contextData.targetWindow;
			var targetFrame = _targetWindow["selectPeopleFrane_" + contextData.id];
			selectOrg.handleOk(contextData, function (ok) {
				if (ok) {
					selectOrg.destroy(contextData);
				}
			});
		});
		/** 清空 */
		$dialogBody.find(".clear").bind("click", context, function (event) {
			var contextData = event.data;
			var _targetWindow = contextData.targetWindow;
			var targetFrame = _targetWindow["selectPeopleFrane_" + contextData.id];
			var selectPeopleWin = targetFrame.contentWindow;
			if (!selectPeopleWin) {
				//IE
				selectPeopleWin = targetFrame.window;
			}
			if (selectPeopleWin && selectPeopleWin.clearSelected) {
				selectPeopleWin.clearSelected();
			}
		});
		/** 切换单位 */
		$dialogBody.find(".account-label").bind("mousedown mouseup mousemove", context, function (e) {
			// if($(this).hasClass(CLASS_NAME_DISABLED)){
			if (hasClass($(this), CLASS_NAME_DISABLED)) {
				// disable不能切换单位
				return;
			}
			var eventObj = stopAndReturn(e);
			if (eventObj.type.toLowerCase() !== "mouseup") {
				return;
			}
			var contextData = eventObj.data;
			var _targetWindow = contextData.targetWindow;
			var targetFrame = _targetWindow["selectPeopleFrane_" + contextData.id];
			var selectPeopleWin = targetFrame.contentWindow;
			if (!selectPeopleWin) {
				//IE
				selectPeopleWin = targetFrame.window;
			}
			if (selectPeopleWin) {
				var $icon = _targetWindow.$("#selectPeople_" + contextData.id).find(".account-label .selectorg-arrow-down");
				// if($icon.hasClass("rolling_btn_b")){
				if (hasClass($icon, "rolling_btn_b")) {
					// 调用切换单位
					if (selectPeopleWin.openAccountSelector) {
						selectPeopleWin.openAccountSelector();
					}
					$icon.removeClass("rolling_btn_b").addClass("rolling_btn_t");
				} else if (hasClass($icon, "rolling_btn_t")) {
					// 调用关闭切换单位
					selectOrg.doCloseAccountSelector(contextData);
				}
			}
		});
		/** 取消|关闭 */
		$dialogBody.find(".cancel,.selectorg-setwin").bind("click", context, function (event) {
			var contextData = event.data;
			var options = contextData.options;
			if (options.canclecallback) {
				options.canclecallback();
			}
			selectOrg.destroy(contextData);
		});
		/** 关闭选择器 */
		$dialogBody.find(".selectorg-btn").bind("click", context, function (event) {
			var contextData = event.data;
			// 关闭选择器
			selectOrg.doCloseAccountSelector(contextData);
		});
		$dialogMask.bind("click", context, function (event) {
			var contextData = event.data;
			// 关闭选择器
			selectOrg.doCloseAccountSelector(contextData);
		});

	}
	/** 关闭切换单位 */
	selectOrg.doOpenAccountSelector = function (context, noTrigger) {
		var _targetWindow = context.targetWindow;
		var targetFrame = _targetWindow["selectPeopleFrane_" + context.id];
		var selectPeopleWin = targetFrame.contentWindow;
		if (!selectPeopleWin) {
			//IE
			selectPeopleWin = targetFrame.window;
		}
		var $icon = _targetWindow.$("#selectPeople_" + context.id).find(".account-label .selectorg-arrow-down");
		if (!hasClass($icon, "rolling_btn_b")) {
			return;
		}
		// 调用切换单位
		if (!noTrigger && selectPeopleWin.openAccountSelector) {
			selectPeopleWin.openAccountSelector();
		}
		$icon.removeClass("rolling_btn_b").addClass("rolling_btn_t");
	}
	/** 关闭切换单位 */
	selectOrg.doCloseAccountSelector = function (context, noTrigger) {
		var _targetWindow = context.targetWindow;
		var targetFrame = _targetWindow["selectPeopleFrane_" + context.id];
		var selectPeopleWin = targetFrame.contentWindow;
		if (!selectPeopleWin) {
			//IE
			selectPeopleWin = targetFrame.window;
		}
		var $icon = _targetWindow.$("#selectPeople_" + context.id).find(".account-label .selectorg-arrow-down");
		if (!hasClass($icon, "rolling_btn_t")) {
			return;
		}
		// 调用切换单位
		if (!noTrigger && selectPeopleWin.closeAccountSelector) {
			selectPeopleWin.closeAccountSelector();
		}
		$icon.addClass("rolling_btn_b").removeClass("rolling_btn_t");
	}
	/** 处理页面点击确定事件 */
	selectOrg.handleOk = function (contextData, callback) {
		var _targetWindow = contextData.targetWindow;
		var targetFrame = _targetWindow["selectPeopleFrane_" + contextData.id];
		var selectPeopleWin = targetFrame.contentWindow;
		if (!selectPeopleWin) {
			//IE
			selectPeopleWin = targetFrame.window;
		}
		if (!selectPeopleWin.OK) {
			callback(false);
			return;
		}
		var options = contextData.options;
		var isCheckSelectedData = true;
		if (!options.showFlowText) {
			// 非串发全部校验重复
			var pObj = _targetWindow.document.getElementById("sequence");
			pObj == null ? document.getElementById("sequence") : pObj;
			if (pObj) {
				isCheckSelectedData = pObj.checked === false;
			}
		}
		//BUG_普通_V8.2_原厂OS服务_中国建材集团有限公司_分送提示：发送失败，收文单位未设置收文交换流程_BUG2023112880333
		if(options.hasOwnProperty('app') && options.app ==='edoc'&& options.hasOwnProperty('isCheckInclusionRelations') && options.isCheckInclusionRelations ===false){
			isCheckSelectedData = false
		}

		/**
		 * 处理返回值
		 * @param _retv
		 */
		function validateCallback(_retv) {
			if (window._isDevelop && window.console) {
				window.console.log("validate_retv", _retv);
			}
			if (_retv === -1) {
				callback(false);
				return;
			}
			var retv = JSON.parse(toJson(_retv));
			// 工作流数据需要包装
			if (retv && options.showFlowTypeRadio) {
				var flowtypes = _targetWindow.document.getElementsByName("flowtype");
				for (var i = 0; i < flowtypes.length; i++) {
					if (!flowtypes[i].checked) {
						continue;
					}
					flowtypes = flowtypes[i].value;
					break;
				}
				retv.obj = [retv.obj, flowtypes];
			}
			var cl = true;
			if (retv) {
				if (options.callbk && options.callbk(retv)) {
					cl = false;
				}
				if (options.callback && options.callback(retv, options)) {
					cl = false;
				}
			}
			// 校验不通过
			if (!cl) {
				callback(false);
				return;
			}

			if (!window.isVjoinSelectOrg) {
				var recentMember = [];
				var retvalueDate = retv.value.split(",");
				for (var i = 0; i < retvalueDate.length; i++) {
					var retvalueItem = retvalueDate[i];
					if (retvalueItem.indexOf("Member") !== 0) {
						continue;
					}
					var memberItem = retvalueItem;
					if (retvalueItem.indexOf("#") > -1) {
						var memberIdInfo = retvalueItem.split("|")[1];
						var memberId = memberIdInfo.split("#")[1];
						memberItem = "Member|" + memberId;
					}
					recentMember.push(memberItem);
					if (recentMember.length >= 30) {
						break;
					}
				}
				if (recentMember.length) {
					$.ajax({
						type: "POST",
						beforeSend: _csrfGuard.beforeAjaxSend,
						url: _selectOrgPath + "/organization/orgIndexController.do?method=saveRecentData4OrgIndex&rData=" + encodeURI(recentMember.join(","))
					});
				}
			}
			callback(true);
		}

		selectPeopleWin.OK({
			validateCallback: validateCallback,
			isCheckSelectedData: isCheckSelectedData
		});
	}
	/** destroy instance */
	selectOrg.destroy = function (contextData) {
		// destroy drag instance
		if (selectOrg._dragObj != null) {
			selectOrg._dragObj.destroy();
			selectOrg._dragObj = null;
		}

		var _targetWindow = contextData.targetWindow;
		var $dialogBody = _targetWindow.$("#selectPeople_" + contextData.id);
		var $dialogShade = _targetWindow.$("#selectPeopleShade_" + contextData.id);
		var $dialogMove = _targetWindow.$("#selectPeopleMove_" + contextData.id);
		var $dialogIframe = _targetWindow.$("#selectPeopleIframe_" + contextData.id);

		// unbind event
		$dialogBody.find(".ok,.clear,.cancel,.selectorg-setwin,.account-label,.selectorg-btn").unbind("click");
		$dialogShade.unbind("click");
		// destroy dom
		$dialogMove.remove();
		$dialogBody.remove();
		$dialogShade.remove();
		$dialogIframe.remove();

		// undefine dialog transParams method
		_targetWindow.selectOrgObj = null;

		if (window.showOfficeObj) {
			showOfficeObj();
		}
		window._selectOrgInstance_ = null;
	}
	/** destroy instance */
	selectOrg.updateSelectOrgSwitchAccount = function (params, contextData) {
		var _targetWindow = contextData.targetWindow;
		var $dialogBody = _targetWindow.$("#selectPeople_" + contextData.id);

		$dialogBody.find(".default-label").css("display", "none");

		var $accountLabel = $dialogBody.find(".account-label").css("display", "inline-block");
		var $accountName = $accountLabel.find(".account-name").text(params.accountName);
		var $icon = $accountLabel.find(".selectorg-arrow-down").css("display", "inline-block");
		$icon.addClass("rolling_btn_b").removeClass("rolling_btn_t");

		if (params.disabled) {
			$accountLabel.addClass(CLASS_NAME_DISABLED);
			$accountLabel.find(".selectorg-arrow-down").css("display", "none");
		} else {
			$accountLabel.removeClass(CLASS_NAME_DISABLED);
			$accountLabel.find(".selectorg-arrow-down").css("display", "inline-block");
		}
	}
	/** 处理应用参数 */
	selectOrg.dealOptions = function (options) {
		if (options.preCallback) {
			options.preCallback(options);
		}
		var settings = $.extend({}, options);
		// 公告模块，适配，如果传了_window，则使用传过来的_window
		if (!options._window) {
			// 老选人
			settings._window = window;
		}
		if (_select_org_version_ === "vue") {
			// 新选人
			settings.preCallback = '';
			settings.canclecallback = '';
			settings.callbk = '';
			settings.callback = '';
			// 可能传入的数据是JSON Object
			if (options.excludeElements && options.excludeElements instanceof Array) {
				var excludeElements = options.excludeElements;
				var _excludeElements = [];
				for (var i = 0; i < excludeElements.length; i++) {
					_excludeElements.push(excludeElements[i].type + "|" + excludeElements[i].id)
				}
				options.excludeElements = _excludeElements.join(",");
			}
		}
		return settings;
	}
	selectOrg.open = function (options) {
		if (window._selectOrgInstance_ != null) {
			return;
		}
		window._selectOrgInstance_ = this;
		try {
			selectOrg._open(options);
		}catch (e){
			window._selectOrgInstance_ = null;
			console.warn("selectOrg open error",e);
		}
		
	}
	/** 打开选人界面 */
	selectOrg._open = function (options) {
		
		if (!options) {
			options = {};
		}
		if (window._isDevelop && window.console) {
			window.console.log(toJson(options));
		}
		var settings = selectOrg.dealOptions(options);
		if (window._isDevelop && window.console) {
			window.console.log("dealOptions", toJson(settings));
		}
		var url = _selectOrgPath + '/selectpeople.do?method=index&sdk=true';
		if (options.showAllAccount) {
			url += "&showAllAccount=" + options.showAllAccount;
		}
		if (options.onlyShowChildrenAccount) {
			url += "&onlyShowChildrenAccount=" + options.onlyShowChildrenAccount;
		}
		if (options.showAccountIds) {
			url += "&showAccountIds=" + options.showAccountIds;
		}
		url += "&selectOrgVersion=" + _select_org_version_;
		url += _csrfGuard.getUrlSurffix();
		var context = {
			url: url,
			id: new Date().getTime() + "",
			targetWindow: _targetWindow,
			options: options
		}
		// define selectOrgObj
		_targetWindow.selectOrgObj = {
			// transParams
			getParams: function () {
				return settings;
			},
			// 切换单位
			updateSwitchAccount: function (params) {
				selectOrg.updateSelectOrgSwitchAccount(params, context);
			},
			// 关闭
			closeAccountSelector: function () {
				var _targetWindow = context.targetWindow;
				var $icon = _targetWindow.$("#selectPeople_" + context.id).find(".account-label .selectorg-arrow-down");
				$icon.addClass("rolling_btn_b").removeClass("rolling_btn_t");
			},
			// 开启
			openAccountSelector: function () {
				var _targetWindow = context.targetWindow;
				var $icon = _targetWindow.$("#selectPeople_" + context.id).find(".account-label .selectorg-arrow-down");
				$icon.addClass("rolling_btn_t").removeClass("rolling_btn_b");
			},
			// 停用
			disableAccountSelector: function () {
				var _targetWindow = context.targetWindow;
				var $accountLabel = _targetWindow.$("#selectPeople_" + context.id).find(".account-label");
				$accountLabel.addClass(CLASS_NAME_DISABLED);
				var $icon = $accountLabel.find(".selectorg-arrow-down");
				$icon.css("display", "none");
			},
			// 启用
			enableAccountSelector: function () {
				var _targetWindow = context.targetWindow;
				var $accountLabel = _targetWindow.$("#selectPeople_" + context.id).find(".account-label");
				$accountLabel.removeClass(CLASS_NAME_DISABLED);
				var $icon = $accountLabel.find(".selectorg-arrow-down");
				$icon.css("display", "inline-block").addClass("rolling_btn_b").removeClass("rolling_btn_t");
			},
			// 更新label
			updateLabel: function (params) {
				var _targetWindow = context.targetWindow;
				var $dialogBody = _targetWindow.$("#selectPeople_" + context.id);
				$dialogBody.find(".account-label").css("display", "none");
				$dialogBody.find(".default-label").show().text(params.label);
			},
			// showbarMask
			showbarMask: function (params) {
				var _targetWindow = context.targetWindow;
				_targetWindow.$("#selectPeople_" + context.id).addClass("selectorg-showMask");
			},
			// hidebarMask
			hidebarMask: function (params) {
				var _targetWindow = context.targetWindow;
				_targetWindow.$("#selectPeople_" + context.id).removeClass("selectorg-showMask");
			},
			// 隐藏确定按钮
			hideOperationBtn: function (params) {
				var _targetWindow = context.targetWindow;
				var $dialogBody = _targetWindow.$("#selectPeople_" + context.id);
				var $okElement = $dialogBody.find(".ok")
				var $flowElement = $dialogBody.find(".flowbtns")
				$okElement.css("display", "none")
				$flowElement.css("display", "none")
			}
		}

		// generate dom
		var $dialogBody = selectOrg.getDialogBody(context)
		$dialogBody.find(".flowbtns").append(selectOrg.getFlowBtn(context));
		_targetWindow.$("body").append($dialogBody);

		// bind event
		selectOrg.initEvent(context);

		// 隐藏office空间
		if (window.hideOfficeObj) {
			window.hideOfficeObj();
		}
	}

	var defultOpt = {
		cancel: function () { },
		ok: function () { },
		transParams: {
			// dialogName 为空时加载默认自定义页面
			'dialogName': ''
		}
	};

	function toJson(options) {
		try {
			return JSON.stringify(options, function (k, v) {
				if (v === null || typeof v === "undefined") {
					return "";
				}
				if (v.location) {
					return "";
				}
				return v;
			})
		} catch (e) {
			window.console.log(e);
		}
		return "";
	}

	/**
	 * 获取弹出层宽度
	 * @returns {number}
	 */
	var getDialogWidth = function () {
		var _clientWidth = _targetWindow.innerWidth || _targetWindow.document.documentElement.clientWidth || _targetWindow.document.body.clientWidth;
		return _clientWidth >= 1600 ? (_clientWidth - 40) : (_clientWidth - 20);
	};

	/**
	 * 获取弹出层高度
	 * @returns {number}
	 */
	var getDialogHeight = function () {
		var _clientHeight = _targetWindow.innerHeight || _targetWindow.document.documentElement.clientHeight || _targetWindow.document.body.clientHeight;
		return _clientHeight >= 740 ? (_clientHeight - 20) : (_clientHeight - 10);
	};

	/**
	 * 显示选人范围选择弹出框
	 * @param params
	 */
	function showSelectConfig(params) {
		var options = $.extend(true, {}, defultOpt, params);
		// 打开自定义选人
		var dialog = _targetWindow.$.dialog({
			id: "SelectOrgConfigDialog",
			url: _selectOrgPath + "/apps_res/organization/cap4SelectOrg/cap4SelectOrg.html" + _resSuffix + _csrfGuard.getUrlSurffix(),
			width: getDialogWidth(),
			height: getDialogHeight(),
			title: _i18n("common.pleaseSelect.label"),
			closeParam: {
				show: true,
				handler: function () {
					options.cancel();
				}
			},
			transParams: params.transParams,
			targetWindow: _targetWindow,
			buttons: [{
				text: $.i18n('common.button.ok.label'),
				isEmphasize: true,
				handler: function () {
					var retVal = dialog.getReturnValue();
					options.ok({
						success: !!retVal,
						selectOrg: retVal
					});
					dialog.close();
				}
			},
			{
				text: $.i18n('common.button.cancel.label'),
				handler: function () {
					options.cancel();
					dialog.close();
				}
			}],
		});
	}

	// export
	window.selectOrgSdk = {
		/**
		 * 显示选人外框
		 */
		showSelectOrg: selectOrg.open,
		/**
		 * 显示选人范围选择弹出框
		 */
		showSelectConfig: showSelectConfig
	};

	// 如果全局不存在选人
	jqueryCallback(function (){
		if ($ && !$.selectPeople) {
			$.selectPeople = function (options) {
				if (selectOrg) {
					return selectOrg.open(options);
				} else {
					return window.top.$.selectPeople(options)
				}
			}
		}
	});

})(function () {
	if (window.jQuery) {
		return window.jQuery;
	}
	try {
		var _targetWindow = window.getCtpTop ? window.getCtpTop() : window.getA8Top();
		return _targetWindow.jQuery;
	} catch (e) {
		console.warn(e);
	}
	return undefined;
}());
